{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Dynamic Quantum Chemistry Workflow \n",
    "\n",
    "NOTE: Make sure to use Python 3.9 or higher for this, `pymatgen` package does not support Python 3.8 or lower.\n",
    "\n",
    "In this tutorial, we discuss how _covalent_ can be used to construct and manage dynamic workflows that are common in quantum-chemical simulations. In this example, given a crystal structure, we seek to do the following:\n",
    "\n",
    "1. Relax the atomic positions and cell volume for the structure (i.e. find the local minimum energy configuration).\n",
    "2. Carve all possible surface slabs of the relaxed structure.\n",
    "3. For each generated slab, relax the atomic positions of each structure.\n",
    "\n",
    "This will be done using the materials informatics library [Pymatgen](https://github.com/materialsproject/pymatgen) and a machine learned interatomic potential called [M3GNet](https://www.nature.com/articles/s43588-022-00349-3). Because the number of slabs is only known at runtime, this is a [dynamic workflow](https://covalent.readthedocs.io/en/latest/developer/patterns/dynamic_workflow.html) and we must take advantage of the [sublattice](https://covalent.readthedocs.io/en/latest/glossary/index.html#term-Sublattice) feature in Covalent to properly dispatch the workflow."
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "First, we need to install the necessary Python packages from the provided `requirements.txt` file (e.g. `pip install -r requirements.txt`). These are printed below:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "covalent\n",
      "pymatgen[relaxation]==2023.9.25\n"
     ]
    }
   ],
   "source": [
    "with open(\"requirements.txt\", \"r\") as file:\n",
    "    for line in file:\n",
    "        print(line.rstrip())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If you're using mac then you might also have to install the following packages with homebrew as:\n",
    "\n",
    "```\n",
    "brew install freetype pkg-config libpng\n",
    "``````"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Once that is done, we can import the necessary functions for this tutorial:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import covalent as ct\n",
    "\n",
    "from pymatgen.core import Structure\n",
    "from pymatgen.core.surface import generate_all_slabs"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then will make sure the Covalent server is started:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Covalent server is already running.\n"
     ]
    }
   ],
   "source": [
    "ct.covalent_start()"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we will define the individual compute tasks. The first `Electron` we will define is a `relax_structure` function, which takes in a Pymatgen `Structure` object as the input and runs the relaxation calculation using M3GNet. It returns an updated `Structure` object. This process can be thought of as the compute-heavy task."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "@ct.electron\n",
    "def relax_structure(structure, relax_cell=True):\n",
    "    return structure.relax(relax_cell=relax_cell)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we will define a separate `Electron` called `carve_slabs` that takes in a `Structure` object and carves all plausible surface slabs, which it returns as a list of new `Structure` objects. This is a relatively quick task, but we still need to define it as an `Electron` so that it can be used appropriately in the workflow."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "@ct.electron\n",
    "def carve_slabs(structure, max_index=1, min_slab_size=10.0, min_vacuum_size=10.0):\n",
    "    slabs = generate_all_slabs(\n",
    "        structure,\n",
    "        max_index,\n",
    "        min_slab_size,\n",
    "        min_vacuum_size,\n",
    "    )\n",
    "    return slabs"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now, for the most subtle but important bit. We need to define a sublattice that will take in the list of slabs and relax each individual slab using the previously defined `relax_structure` `Electron`. The sublattice is crucial here because the number of slabs is only determined at runtime and will vary depending on the input `Structure` object."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "@ct.electron\n",
    "@ct.lattice\n",
    "def relax_slabs(slabs):\n",
    "    return [relax_structure(slab, relax_cell=False) for slab in slabs]"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With these individual `Electron` objects defined, we can now define the overall workflow that stitches them together and forms a `Lattice`. As introduced at the start of this tutorial, there are three major sets of tasks, and those are reflected by the three functions defined above."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "@ct.lattice\n",
    "def workflow(structure):\n",
    "    relaxed_structure = relax_structure(structure)\n",
    "    slabs = carve_slabs(relaxed_structure)\n",
    "    relaxed_slabs = relax_slabs(slabs)\n",
    "    return relaxed_slabs"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we can create an example `Structure` as the input for our workflow. Its structure is shown below."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "structure = Structure(\n",
    "    lattice=[[0, 2.13, 2.13], [2.13, 0, 2.13], [2.13, 2.13, 0]],\n",
    "    species=[\"Mg\", \"O\"],\n",
    "    coords=[[0, 0, 0], [0.5, 0.5, 0.5]],\n",
    ")"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And we finally take this input `Structure` and run it through our newly created workflow."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "dispatch_id = ct.dispatch(workflow)(structure)\n",
    "results = ct.get_result(dispatch_id, wait=True)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The workflow in the Covalent UI looks like the following. Note that when you click on the sublattice in the UI, it will open up a new view that shows the individual tasks that were run.\n",
    "\n",
    "![ui](assets/ui_animation.gif)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The image below shows the input structure on the left and one of the four generated slabs on the right.\n",
    "\n",
    "![slabs](assets/slabgen.png)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And this is the output of the workflow:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Lattice Result\n",
      "==============\n",
      "status: COMPLETED\n",
      "result: [Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 3.012274887854692 30.122748878546922\n",
      " angles : 120.00000000000001 120.00000000000001 59.99999999999999\n",
      " volume : 193.27193999999994\n",
      "      A : 2.608706576064084 0.0 -1.5061374439273467\n",
      "      B : 0.8695688586880276 2.4595121467478056 -1.5061374439273467\n",
      "      C : 0.0 0.0 30.122748878546922\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (-0.06335, -0.04479, 2.149) [-0.01821, -0.01821, 0.06954]\n",
      "PeriodicSite: O (1.804, 1.275, -0.6412) [0.5186, 0.5186, 0.03057]\n",
      "PeriodicSite: Mg (-0.04308, -0.03047, 5.197) [-0.01239, -0.01239, 0.1713]\n",
      "PeriodicSite: O (1.762, 1.246, 2.298) [0.5064, 0.5064, 0.1269]\n",
      "PeriodicSite: Mg (-0.03833, -0.0271, 8.217) [-0.01102, -0.01102, 0.2717]\n",
      "PeriodicSite: O (1.776, 1.255, 5.335) [0.5105, 0.5105, 0.2281]\n",
      "PeriodicSite: Mg (-0.03796, -0.02684, 11.23) [-0.01091, -0.01091, 0.3717]\n",
      "PeriodicSite: O (1.788, 1.265, 8.369) [0.5141, 0.5141, 0.3292]\n",
      "PeriodicSite: Mg (-0.01275, -0.009017, 14.29) [-0.003666, -0.003666, 0.4739]\n",
      "PeriodicSite: O (1.762, 1.246, 11.34) [0.5066, 0.5066, 0.427], Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 3.012274887854692 30.122748878546922\n",
      " angles : 120.00000000000001 59.99999999999999 90.0\n",
      " volume : 193.2719399999999\n",
      "      A : 2.608706576064084 0.0 1.5061374439273465\n",
      "      B : 0.8695688586880287 2.459512146747805 -1.5061374439273467\n",
      "      C : 0.0 0.0 30.122748878546922\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (-0.003667, 0.005186, 1.512) [-0.002108, 0.002108, 0.05042]\n",
      "PeriodicSite: O (1.742, 1.226, 1.502) [0.5015, 0.4985, 0.0497]\n",
      "PeriodicSite: Mg (0.004204, -0.005944, 4.511) [0.002417, -0.002417, 0.1495]\n",
      "PeriodicSite: O (1.737, 1.233, 4.523) [0.4985, 0.5015, 0.1503]\n",
      "PeriodicSite: Mg (-2.373e-07, 1.452e-07, 7.531) [-1.106e-07, 5.904e-08, 0.25]\n",
      "PeriodicSite: O (1.739, 1.23, 7.531) [0.5, 0.5, 0.25]\n",
      "PeriodicSite: Mg (-0.004206, 0.005949, 10.55) [-0.002419, 0.002419, 0.3505]\n",
      "PeriodicSite: O (1.742, 1.226, 10.54) [0.5015, 0.4985, 0.3497]\n",
      "PeriodicSite: Mg (0.003665, -0.005183, 13.55) [0.002107, -0.002107, 0.4496]\n",
      "PeriodicSite: O (1.737, 1.233, 13.56) [0.4985, 0.5015, 0.4503], Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 5.217413152128169 48.196398205675074\n",
      " angles : 30.000000000000014 59.99999999999999 73.22134511903964\n",
      " volume : 309.2351039999999\n",
      "      A : 2.608706576064084 0.0 1.5061374439273465\n",
      "      B : -0.869568858688028 2.4595121467478056 4.518412331782038\n",
      "      C : 0.0 0.0 48.196398205675074\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (0.1339, -0.01997, 2.027) [0.04861, -0.008121, 0.04131]\n",
      "PeriodicSite: O (1.084, 1.0, 3.395) [0.5509, 0.4068, 0.01508]\n",
      "PeriodicSite: Mg (0.1856, 0.2225, 4.95) [0.1013, 0.09047, 0.09106]\n",
      "PeriodicSite: O (0.9559, 1.166, 6.628) [0.5245, 0.4742, 0.07668]\n",
      "PeriodicSite: Mg (0.09665, 0.08853, 8.116) [0.04905, 0.036, 0.1635]\n",
      "PeriodicSite: O (0.9216, 1.175, 9.7) [0.5125, 0.4777, 0.1405]\n",
      "PeriodicSite: Mg (0.04673, 0.1156, 11.22) [0.03359, 0.04702, 0.2272]\n",
      "PeriodicSite: O (0.8436, 1.125, 12.85) [0.4758, 0.4574, 0.2088]\n",
      "PeriodicSite: Mg (-0.005373, 0.07126, 14.32) [0.007599, 0.02897, 0.2941]\n",
      "PeriodicSite: O (0.7974, 1.125, 15.94) [0.4581, 0.4574, 0.2735]\n",
      "PeriodicSite: Mg (-0.06382, 0.06227, 17.43) [-0.01603, 0.02532, 0.3598]\n",
      "PeriodicSite: O (0.7609, 1.136, 19.01) [0.4456, 0.4618, 0.3373]\n",
      "PeriodicSite: Mg (-0.07782, 0.05423, 20.47) [-0.02248, 0.02205, 0.4233]\n",
      "PeriodicSite: O (0.7283, 1.092, 22.08) [0.4271, 0.4439, 0.4032]\n",
      "PeriodicSite: Mg (-0.1775, 0.196, 23.65) [-0.04147, 0.07969, 0.4846]\n",
      "PeriodicSite: O (0.727, 1.229, 25.1) [0.4452, 0.4996, 0.46], Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 5.217413152128169 42.17184842996569\n",
      " angles : 29.99999999999997 59.999999999999986 54.735610317245346\n",
      " volume : 270.58071599999977\n",
      "      A : 2.608706576064084 0.0 1.5061374439273465\n",
      "      B : 0.8695688586880266 2.4595121467478043 4.51841233178204\n",
      "      C : 0.0 0.0 42.17184842996569\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (-0.02746, -0.07768, 1.554) [2.276e-07, -0.03158, 0.04023]\n",
      "PeriodicSite: O (1.734, 1.216, 4.527) [0.5, 0.4945, 0.0365]\n",
      "PeriodicSite: Mg (0.02554, 0.07223, 4.474) [1.088e-06, 0.02937, 0.1029]\n",
      "PeriodicSite: O (1.746, 1.25, 7.518) [0.5, 0.5081, 0.106]\n",
      "PeriodicSite: Mg (0.004413, 0.01248, 7.523) [1.247e-07, 0.005074, 0.1778]\n",
      "PeriodicSite: O (1.736, 1.22, 10.55) [0.5, 0.4962, 0.1791]\n",
      "PeriodicSite: Mg (5.245e-07, 2.488e-06, 10.54) [-1.362e-07, 1.012e-06, 0.25]\n",
      "PeriodicSite: O (1.739, 1.23, 13.56) [0.5, 0.5, 0.25]\n",
      "PeriodicSite: Mg (-0.004412, -0.01248, 13.56) [-5.311e-08, -0.005073, 0.3222]\n",
      "PeriodicSite: O (1.742, 1.239, 16.56) [0.5, 0.5038, 0.3209]\n",
      "PeriodicSite: Mg (-0.02554, -0.07224, 16.61) [-3.741e-08, -0.02937, 0.3971]\n",
      "PeriodicSite: O (1.732, 1.21, 19.59) [0.5, 0.4919, 0.394]\n",
      "PeriodicSite: Mg (0.02746, 0.07767, 19.53) [-2.13e-08, 0.03158, 0.4598]\n",
      "PeriodicSite: O (1.744, 1.243, 22.58) [0.5, 0.5055, 0.4635]]\n",
      "input args: None\n",
      "input kwargs: None\n",
      "error: None\n",
      "\n",
      "start_time: 2024-01-07 18:47:40.318085\n",
      "end_time: 2024-01-07 18:47:50.077092\n",
      "\n",
      "results_dir: /Users/neptune/.cache/covalent/results/0de284ad-fecb-4c76-ba03-c4dd8d8b3103\n",
      "dispatch_id: 0de284ad-fecb-4c76-ba03-c4dd8d8b3103\n",
      "\n",
      "Node Outputs\n",
      "------------\n",
      "relax_structure(0): Full Formula (Mg1 O1)\n",
      "Reduced Formula: MgO\n",
      "abc   :   3.012275   3.012275   3.012275\n",
      "angles:  60.000000  60.000000  60.000000\n",
      "pbc   :       True       True       True\n",
      "Sites (2)\n",
      "  #  SP      a    b    c\n",
      "---  ----  ---  ---  ---\n",
      "  0  Mg    0    0    0\n",
      "  1  O     0.5  0.5  0.5\n",
      ":parameter:Full Formula (Mg1 O1)\n",
      "Reduced Formula: MgO\n",
      "abc   :   3.012275   3.012275   3.012275\n",
      "angles:  60.000000  60.000000  60.000000\n",
      "pbc   :       True       True       True\n",
      "Sites (2)\n",
      "  #  SP      a    b    c\n",
      "---  ----  ---  ---  ---\n",
      "  0  Mg    0    0    0\n",
      "  1  O     0.5  0.5  0.5(1): Full Formula (Mg1 O1)\n",
      "Reduced Formula: MgO\n",
      "abc   :   3.012275   3.012275   3.012275\n",
      "angles:  60.000000  60.000000  60.000000\n",
      "pbc   :       True       True       True\n",
      "Sites (2)\n",
      "  #  SP      a    b    c\n",
      "---  ----  ---  ---  ---\n",
      "  0  Mg    0    0    0\n",
      "  1  O     0.5  0.5  0.5\n",
      "carve_slabs(2): [Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 3.012274887854692 30.122748878546922\n",
      " angles : 120.00000000000001 120.00000000000001 59.99999999999999\n",
      " volume : 193.27193999999994\n",
      "      A : 2.608706576064084 0.0 -1.5061374439273467\n",
      "      B : 0.8695688586880276 2.4595121467478056 -1.5061374439273467\n",
      "      C : 0.0 0.0 30.122748878546922\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (0.0, 0.0, 2.259) [0.0, 0.0, 0.075]\n",
      "PeriodicSite: O (1.739, 1.23, -0.7531) [0.5, 0.5, 0.025]\n",
      "PeriodicSite: Mg (0.0, 0.0, 5.271) [0.0, 0.0, 0.175]\n",
      "PeriodicSite: O (1.739, 1.23, 2.259) [0.5, 0.5, 0.125]\n",
      "PeriodicSite: Mg (0.0, 0.0, 8.284) [0.0, 0.0, 0.275]\n",
      "PeriodicSite: O (1.739, 1.23, 5.271) [0.5, 0.5, 0.225]\n",
      "PeriodicSite: Mg (0.0, 0.0, 11.3) [0.0, 0.0, 0.375]\n",
      "PeriodicSite: O (1.739, 1.23, 8.284) [0.5, 0.5, 0.325]\n",
      "PeriodicSite: Mg (0.0, 0.0, 14.31) [0.0, 0.0, 0.475]\n",
      "PeriodicSite: O (1.739, 1.23, 11.3) [0.5, 0.5, 0.425], Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 3.012274887854692 30.122748878546922\n",
      " angles : 120.00000000000001 59.99999999999999 90.0\n",
      " volume : 193.2719399999999\n",
      "      A : 2.608706576064084 0.0 1.5061374439273465\n",
      "      B : 0.8695688586880287 2.459512146747805 -1.5061374439273467\n",
      "      C : 0.0 0.0 30.122748878546922\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (0.0, 0.0, 1.506) [0.0, 0.0, 0.05]\n",
      "PeriodicSite: O (1.739, 1.23, 1.506) [0.5, 0.5, 0.05]\n",
      "PeriodicSite: Mg (0.0, 0.0, 4.518) [0.0, 0.0, 0.15]\n",
      "PeriodicSite: O (1.739, 1.23, 4.518) [0.5, 0.5, 0.15]\n",
      "PeriodicSite: Mg (0.0, 0.0, 7.531) [0.0, 0.0, 0.25]\n",
      "PeriodicSite: O (1.739, 1.23, 7.531) [0.5, 0.5, 0.25]\n",
      "PeriodicSite: Mg (0.0, 0.0, 10.54) [0.0, 0.0, 0.35]\n",
      "PeriodicSite: O (1.739, 1.23, 10.54) [0.5, 0.5, 0.35]\n",
      "PeriodicSite: Mg (0.0, 0.0, 13.56) [0.0, 0.0, 0.45]\n",
      "PeriodicSite: O (1.739, 1.23, 13.56) [0.5, 0.5, 0.45], Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 5.217413152128169 48.196398205675074\n",
      " angles : 30.000000000000014 59.99999999999999 73.22134511903964\n",
      " volume : 309.2351039999999\n",
      "      A : 2.608706576064084 0.0 1.5061374439273465\n",
      "      B : -0.869568858688028 2.4595121467478056 4.518412331782038\n",
      "      C : 0.0 0.0 48.196398205675074\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (0.0, 0.0, 2.259) [0.0, 0.0, 0.04688]\n",
      "PeriodicSite: O (0.8696, 1.23, 3.765) [0.5, 0.5, 0.01562]\n",
      "PeriodicSite: Mg (0.0, 0.0, 5.271) [0.0, 0.0, 0.1094]\n",
      "PeriodicSite: O (0.8696, 1.23, 6.778) [0.5, 0.5, 0.07812]\n",
      "PeriodicSite: Mg (0.0, 0.0, 8.284) [0.0, 0.0, 0.1719]\n",
      "PeriodicSite: O (0.8696, 1.23, 9.79) [0.5, 0.5, 0.1406]\n",
      "PeriodicSite: Mg (0.0, 0.0, 11.3) [0.0, 0.0, 0.2344]\n",
      "PeriodicSite: O (0.8696, 1.23, 12.8) [0.5, 0.5, 0.2031]\n",
      "PeriodicSite: Mg (0.0, 0.0, 14.31) [0.0, 0.0, 0.2969]\n",
      "PeriodicSite: O (0.8696, 1.23, 15.81) [0.5, 0.5, 0.2656]\n",
      "PeriodicSite: Mg (0.0, 0.0, 17.32) [0.0, 0.0, 0.3594]\n",
      "PeriodicSite: O (0.8696, 1.23, 18.83) [0.5, 0.5, 0.3281]\n",
      "PeriodicSite: Mg (0.0, 0.0, 20.33) [0.0, 0.0, 0.4219]\n",
      "PeriodicSite: O (0.8696, 1.23, 21.84) [0.5, 0.5, 0.3906]\n",
      "PeriodicSite: Mg (0.0, 0.0, 23.35) [0.0, 0.0, 0.4844]\n",
      "PeriodicSite: O (0.8696, 1.23, 24.85) [0.5, 0.5, 0.4531], Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 5.217413152128169 42.17184842996569\n",
      " angles : 29.99999999999997 59.999999999999986 54.735610317245346\n",
      " volume : 270.58071599999977\n",
      "      A : 2.608706576064084 0.0 1.5061374439273465\n",
      "      B : 0.8695688586880266 2.4595121467478043 4.51841233178204\n",
      "      C : 0.0 0.0 42.17184842996569\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (0.0, 0.0, 1.506) [0.0, 0.0, 0.03571]\n",
      "PeriodicSite: O (1.739, 1.23, 4.518) [0.5, 0.5, 0.03571]\n",
      "PeriodicSite: Mg (0.0, 0.0, 4.518) [0.0, 0.0, 0.1071]\n",
      "PeriodicSite: O (1.739, 1.23, 7.531) [0.5, 0.5, 0.1071]\n",
      "PeriodicSite: Mg (0.0, 0.0, 7.531) [0.0, 0.0, 0.1786]\n",
      "PeriodicSite: O (1.739, 1.23, 10.54) [0.5, 0.5, 0.1786]\n",
      "PeriodicSite: Mg (0.0, 0.0, 10.54) [0.0, 0.0, 0.25]\n",
      "PeriodicSite: O (1.739, 1.23, 13.56) [0.5, 0.5, 0.25]\n",
      "PeriodicSite: Mg (0.0, 0.0, 13.56) [0.0, 0.0, 0.3214]\n",
      "PeriodicSite: O (1.739, 1.23, 16.57) [0.5, 0.5, 0.3214]\n",
      "PeriodicSite: Mg (0.0, 0.0, 16.57) [0.0, 0.0, 0.3929]\n",
      "PeriodicSite: O (1.739, 1.23, 19.58) [0.5, 0.5, 0.3929]\n",
      "PeriodicSite: Mg (0.0, 0.0, 19.58) [0.0, 0.0, 0.4643]\n",
      "PeriodicSite: O (1.739, 1.23, 22.59) [0.5, 0.5, 0.4643]]\n",
      ":sublattice:relax_slabs(3): [Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 3.012274887854692 30.122748878546922\n",
      " angles : 120.00000000000001 120.00000000000001 59.99999999999999\n",
      " volume : 193.27193999999994\n",
      "      A : 2.608706576064084 0.0 -1.5061374439273467\n",
      "      B : 0.8695688586880276 2.4595121467478056 -1.5061374439273467\n",
      "      C : 0.0 0.0 30.122748878546922\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (-0.06335, -0.04479, 2.149) [-0.01821, -0.01821, 0.06954]\n",
      "PeriodicSite: O (1.804, 1.275, -0.6412) [0.5186, 0.5186, 0.03057]\n",
      "PeriodicSite: Mg (-0.04308, -0.03047, 5.197) [-0.01239, -0.01239, 0.1713]\n",
      "PeriodicSite: O (1.762, 1.246, 2.298) [0.5064, 0.5064, 0.1269]\n",
      "PeriodicSite: Mg (-0.03833, -0.0271, 8.217) [-0.01102, -0.01102, 0.2717]\n",
      "PeriodicSite: O (1.776, 1.255, 5.335) [0.5105, 0.5105, 0.2281]\n",
      "PeriodicSite: Mg (-0.03796, -0.02684, 11.23) [-0.01091, -0.01091, 0.3717]\n",
      "PeriodicSite: O (1.788, 1.265, 8.369) [0.5141, 0.5141, 0.3292]\n",
      "PeriodicSite: Mg (-0.01275, -0.009017, 14.29) [-0.003666, -0.003666, 0.4739]\n",
      "PeriodicSite: O (1.762, 1.246, 11.34) [0.5066, 0.5066, 0.427], Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 3.012274887854692 30.122748878546922\n",
      " angles : 120.00000000000001 59.99999999999999 90.0\n",
      " volume : 193.2719399999999\n",
      "      A : 2.608706576064084 0.0 1.5061374439273465\n",
      "      B : 0.8695688586880287 2.459512146747805 -1.5061374439273467\n",
      "      C : 0.0 0.0 30.122748878546922\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (-0.003667, 0.005186, 1.512) [-0.002108, 0.002108, 0.05042]\n",
      "PeriodicSite: O (1.742, 1.226, 1.502) [0.5015, 0.4985, 0.0497]\n",
      "PeriodicSite: Mg (0.004204, -0.005944, 4.511) [0.002417, -0.002417, 0.1495]\n",
      "PeriodicSite: O (1.737, 1.233, 4.523) [0.4985, 0.5015, 0.1503]\n",
      "PeriodicSite: Mg (-2.373e-07, 1.452e-07, 7.531) [-1.106e-07, 5.904e-08, 0.25]\n",
      "PeriodicSite: O (1.739, 1.23, 7.531) [0.5, 0.5, 0.25]\n",
      "PeriodicSite: Mg (-0.004206, 0.005949, 10.55) [-0.002419, 0.002419, 0.3505]\n",
      "PeriodicSite: O (1.742, 1.226, 10.54) [0.5015, 0.4985, 0.3497]\n",
      "PeriodicSite: Mg (0.003665, -0.005183, 13.55) [0.002107, -0.002107, 0.4496]\n",
      "PeriodicSite: O (1.737, 1.233, 13.56) [0.4985, 0.5015, 0.4503], Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 5.217413152128169 48.196398205675074\n",
      " angles : 30.000000000000014 59.99999999999999 73.22134511903964\n",
      " volume : 309.2351039999999\n",
      "      A : 2.608706576064084 0.0 1.5061374439273465\n",
      "      B : -0.869568858688028 2.4595121467478056 4.518412331782038\n",
      "      C : 0.0 0.0 48.196398205675074\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (0.1339, -0.01997, 2.027) [0.04861, -0.008121, 0.04131]\n",
      "PeriodicSite: O (1.084, 1.0, 3.395) [0.5509, 0.4068, 0.01508]\n",
      "PeriodicSite: Mg (0.1856, 0.2225, 4.95) [0.1013, 0.09047, 0.09106]\n",
      "PeriodicSite: O (0.9559, 1.166, 6.628) [0.5245, 0.4742, 0.07668]\n",
      "PeriodicSite: Mg (0.09665, 0.08853, 8.116) [0.04905, 0.036, 0.1635]\n",
      "PeriodicSite: O (0.9216, 1.175, 9.7) [0.5125, 0.4777, 0.1405]\n",
      "PeriodicSite: Mg (0.04673, 0.1156, 11.22) [0.03359, 0.04702, 0.2272]\n",
      "PeriodicSite: O (0.8436, 1.125, 12.85) [0.4758, 0.4574, 0.2088]\n",
      "PeriodicSite: Mg (-0.005373, 0.07126, 14.32) [0.007599, 0.02897, 0.2941]\n",
      "PeriodicSite: O (0.7974, 1.125, 15.94) [0.4581, 0.4574, 0.2735]\n",
      "PeriodicSite: Mg (-0.06382, 0.06227, 17.43) [-0.01603, 0.02532, 0.3598]\n",
      "PeriodicSite: O (0.7609, 1.136, 19.01) [0.4456, 0.4618, 0.3373]\n",
      "PeriodicSite: Mg (-0.07782, 0.05423, 20.47) [-0.02248, 0.02205, 0.4233]\n",
      "PeriodicSite: O (0.7283, 1.092, 22.08) [0.4271, 0.4439, 0.4032]\n",
      "PeriodicSite: Mg (-0.1775, 0.196, 23.65) [-0.04147, 0.07969, 0.4846]\n",
      "PeriodicSite: O (0.727, 1.229, 25.1) [0.4452, 0.4996, 0.46], Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 5.217413152128169 42.17184842996569\n",
      " angles : 29.99999999999997 59.999999999999986 54.735610317245346\n",
      " volume : 270.58071599999977\n",
      "      A : 2.608706576064084 0.0 1.5061374439273465\n",
      "      B : 0.8695688586880266 2.4595121467478043 4.51841233178204\n",
      "      C : 0.0 0.0 42.17184842996569\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (-0.02746, -0.07768, 1.554) [2.276e-07, -0.03158, 0.04023]\n",
      "PeriodicSite: O (1.734, 1.216, 4.527) [0.5, 0.4945, 0.0365]\n",
      "PeriodicSite: Mg (0.02554, 0.07223, 4.474) [1.088e-06, 0.02937, 0.1029]\n",
      "PeriodicSite: O (1.746, 1.25, 7.518) [0.5, 0.5081, 0.106]\n",
      "PeriodicSite: Mg (0.004413, 0.01248, 7.523) [1.247e-07, 0.005074, 0.1778]\n",
      "PeriodicSite: O (1.736, 1.22, 10.55) [0.5, 0.4962, 0.1791]\n",
      "PeriodicSite: Mg (5.245e-07, 2.488e-06, 10.54) [-1.362e-07, 1.012e-06, 0.25]\n",
      "PeriodicSite: O (1.739, 1.23, 13.56) [0.5, 0.5, 0.25]\n",
      "PeriodicSite: Mg (-0.004412, -0.01248, 13.56) [-5.311e-08, -0.005073, 0.3222]\n",
      "PeriodicSite: O (1.742, 1.239, 16.56) [0.5, 0.5038, 0.3209]\n",
      "PeriodicSite: Mg (-0.02554, -0.07224, 16.61) [-3.741e-08, -0.02937, 0.3971]\n",
      "PeriodicSite: O (1.732, 1.21, 19.59) [0.5, 0.4919, 0.394]\n",
      "PeriodicSite: Mg (0.02746, 0.07767, 19.53) [-2.13e-08, 0.03158, 0.4598]\n",
      "PeriodicSite: O (1.744, 1.243, 22.58) [0.5, 0.5055, 0.4635]]\n",
      ":parameter:<covalent._workflow.lattice.Lattice object at 0x2cf2d97f0>(4): <covalent._workflow.lattice.Lattice object at 0x2cf2d97f0>\n",
      ":parameter:{\"executor\": \"dask\", \"workflow_executor\": \"dask\", \"hooks\": {}, \"executor_data\": {}, \"workflow_executor_data\": {}, \"qelectron_data_exists\": false}(5): {\"executor\": \"dask\", \"workflow_executor\": \"dask\", \"hooks\": {}, \"executor_data\": {}, \"workflow_executor_data\": {}, \"qelectron_data_exists\": false}\n",
      ":postprocess:reconstruct(6): [Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 3.012274887854692 30.122748878546922\n",
      " angles : 120.00000000000001 120.00000000000001 59.99999999999999\n",
      " volume : 193.27193999999994\n",
      "      A : 2.608706576064084 0.0 -1.5061374439273467\n",
      "      B : 0.8695688586880276 2.4595121467478056 -1.5061374439273467\n",
      "      C : 0.0 0.0 30.122748878546922\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (-0.06335, -0.04479, 2.149) [-0.01821, -0.01821, 0.06954]\n",
      "PeriodicSite: O (1.804, 1.275, -0.6412) [0.5186, 0.5186, 0.03057]\n",
      "PeriodicSite: Mg (-0.04308, -0.03047, 5.197) [-0.01239, -0.01239, 0.1713]\n",
      "PeriodicSite: O (1.762, 1.246, 2.298) [0.5064, 0.5064, 0.1269]\n",
      "PeriodicSite: Mg (-0.03833, -0.0271, 8.217) [-0.01102, -0.01102, 0.2717]\n",
      "PeriodicSite: O (1.776, 1.255, 5.335) [0.5105, 0.5105, 0.2281]\n",
      "PeriodicSite: Mg (-0.03796, -0.02684, 11.23) [-0.01091, -0.01091, 0.3717]\n",
      "PeriodicSite: O (1.788, 1.265, 8.369) [0.5141, 0.5141, 0.3292]\n",
      "PeriodicSite: Mg (-0.01275, -0.009017, 14.29) [-0.003666, -0.003666, 0.4739]\n",
      "PeriodicSite: O (1.762, 1.246, 11.34) [0.5066, 0.5066, 0.427], Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 3.012274887854692 30.122748878546922\n",
      " angles : 120.00000000000001 59.99999999999999 90.0\n",
      " volume : 193.2719399999999\n",
      "      A : 2.608706576064084 0.0 1.5061374439273465\n",
      "      B : 0.8695688586880287 2.459512146747805 -1.5061374439273467\n",
      "      C : 0.0 0.0 30.122748878546922\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (-0.003667, 0.005186, 1.512) [-0.002108, 0.002108, 0.05042]\n",
      "PeriodicSite: O (1.742, 1.226, 1.502) [0.5015, 0.4985, 0.0497]\n",
      "PeriodicSite: Mg (0.004204, -0.005944, 4.511) [0.002417, -0.002417, 0.1495]\n",
      "PeriodicSite: O (1.737, 1.233, 4.523) [0.4985, 0.5015, 0.1503]\n",
      "PeriodicSite: Mg (-2.373e-07, 1.452e-07, 7.531) [-1.106e-07, 5.904e-08, 0.25]\n",
      "PeriodicSite: O (1.739, 1.23, 7.531) [0.5, 0.5, 0.25]\n",
      "PeriodicSite: Mg (-0.004206, 0.005949, 10.55) [-0.002419, 0.002419, 0.3505]\n",
      "PeriodicSite: O (1.742, 1.226, 10.54) [0.5015, 0.4985, 0.3497]\n",
      "PeriodicSite: Mg (0.003665, -0.005183, 13.55) [0.002107, -0.002107, 0.4496]\n",
      "PeriodicSite: O (1.737, 1.233, 13.56) [0.4985, 0.5015, 0.4503], Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 5.217413152128169 48.196398205675074\n",
      " angles : 30.000000000000014 59.99999999999999 73.22134511903964\n",
      " volume : 309.2351039999999\n",
      "      A : 2.608706576064084 0.0 1.5061374439273465\n",
      "      B : -0.869568858688028 2.4595121467478056 4.518412331782038\n",
      "      C : 0.0 0.0 48.196398205675074\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (0.1339, -0.01997, 2.027) [0.04861, -0.008121, 0.04131]\n",
      "PeriodicSite: O (1.084, 1.0, 3.395) [0.5509, 0.4068, 0.01508]\n",
      "PeriodicSite: Mg (0.1856, 0.2225, 4.95) [0.1013, 0.09047, 0.09106]\n",
      "PeriodicSite: O (0.9559, 1.166, 6.628) [0.5245, 0.4742, 0.07668]\n",
      "PeriodicSite: Mg (0.09665, 0.08853, 8.116) [0.04905, 0.036, 0.1635]\n",
      "PeriodicSite: O (0.9216, 1.175, 9.7) [0.5125, 0.4777, 0.1405]\n",
      "PeriodicSite: Mg (0.04673, 0.1156, 11.22) [0.03359, 0.04702, 0.2272]\n",
      "PeriodicSite: O (0.8436, 1.125, 12.85) [0.4758, 0.4574, 0.2088]\n",
      "PeriodicSite: Mg (-0.005373, 0.07126, 14.32) [0.007599, 0.02897, 0.2941]\n",
      "PeriodicSite: O (0.7974, 1.125, 15.94) [0.4581, 0.4574, 0.2735]\n",
      "PeriodicSite: Mg (-0.06382, 0.06227, 17.43) [-0.01603, 0.02532, 0.3598]\n",
      "PeriodicSite: O (0.7609, 1.136, 19.01) [0.4456, 0.4618, 0.3373]\n",
      "PeriodicSite: Mg (-0.07782, 0.05423, 20.47) [-0.02248, 0.02205, 0.4233]\n",
      "PeriodicSite: O (0.7283, 1.092, 22.08) [0.4271, 0.4439, 0.4032]\n",
      "PeriodicSite: Mg (-0.1775, 0.196, 23.65) [-0.04147, 0.07969, 0.4846]\n",
      "PeriodicSite: O (0.727, 1.229, 25.1) [0.4452, 0.4996, 0.46], Structure Summary\n",
      "Lattice\n",
      "    abc : 3.012274887854692 5.217413152128169 42.17184842996569\n",
      " angles : 29.99999999999997 59.999999999999986 54.735610317245346\n",
      " volume : 270.58071599999977\n",
      "      A : 2.608706576064084 0.0 1.5061374439273465\n",
      "      B : 0.8695688586880266 2.4595121467478043 4.51841233178204\n",
      "      C : 0.0 0.0 42.17184842996569\n",
      "    pbc : True True True\n",
      "PeriodicSite: Mg (-0.02746, -0.07768, 1.554) [2.276e-07, -0.03158, 0.04023]\n",
      "PeriodicSite: O (1.734, 1.216, 4.527) [0.5, 0.4945, 0.0365]\n",
      "PeriodicSite: Mg (0.02554, 0.07223, 4.474) [1.088e-06, 0.02937, 0.1029]\n",
      "PeriodicSite: O (1.746, 1.25, 7.518) [0.5, 0.5081, 0.106]\n",
      "PeriodicSite: Mg (0.004413, 0.01248, 7.523) [1.247e-07, 0.005074, 0.1778]\n",
      "PeriodicSite: O (1.736, 1.22, 10.55) [0.5, 0.4962, 0.1791]\n",
      "PeriodicSite: Mg (5.245e-07, 2.488e-06, 10.54) [-1.362e-07, 1.012e-06, 0.25]\n",
      "PeriodicSite: O (1.739, 1.23, 13.56) [0.5, 0.5, 0.25]\n",
      "PeriodicSite: Mg (-0.004412, -0.01248, 13.56) [-5.311e-08, -0.005073, 0.3222]\n",
      "PeriodicSite: O (1.742, 1.239, 16.56) [0.5, 0.5038, 0.3209]\n",
      "PeriodicSite: Mg (-0.02554, -0.07224, 16.61) [-3.741e-08, -0.02937, 0.3971]\n",
      "PeriodicSite: O (1.732, 1.21, 19.59) [0.5, 0.4919, 0.394]\n",
      "PeriodicSite: Mg (0.02746, 0.07767, 19.53) [-2.13e-08, 0.03158, 0.4598]\n",
      "PeriodicSite: O (1.744, 1.243, 22.58) [0.5, 0.5055, 0.4635]]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print(results)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "new",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.18"
  },
  "vscode": {
   "interpreter": {
    "hash": "65f23ff11413a1b24e6045f226bbb649c5d31fd62a4c12b34b399c99ac705181"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
